import java.util.Comparator;
import java.util.TreeMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2023-02-09
 * Time: 9:38
 */
class Cat implements Comparable<Cat> {
    private String name;
    private int age;
    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Cat o) {
        return this.age - o.age;
    }
}

class Com implements Comparator<Cat>{
    @Override
    public int compare(Cat o1, Cat o2) {
        return o1.compareTo(o2);
    }
}
public class test20 {
    public static void main(String[] args) {
        TreeMap<Cat, Integer> map = new TreeMap<>(new Com());
        map.put(new Cat("张三", 12), 1);
        map.put(new Cat("李四", 21), 2);
        map.put(new Cat("王五", 16), 3);
        System.out.println(map);
    }
}
